package com.bkq.viettravel;

import java.text.ParseException;
import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.app.ListActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListHotel extends ListActivity {
	private LayoutInflater mInflater;
	private Vector<RowData> data;
	RowData rd;

	static final String[] namehotel = new String[] {"Phung Hoang", "ABC", "Au Co","Start","MNB"};
	static final String[] qualityhotel = new String[] {"2*", "7*", "5*","4*","3*"};
	static final String[] adresshotel = new String[] {"Nguyen Luong Bang", "Au Co", "ABC","MKI","YUI"};
	static final String[] phonehotel = new String[] {"44444444444", "333333333", "2222222","055555555","11111"};
	static final String[] mailhotel = new String[] {"1@gmail.com", "7@gmail.com", "3@gmail.com","055555555@gmail.com","sjfhj@gamil.com"};

	static Button bntHome, bntFavorite, bntPlan, bntAbout, bntBack;
	
	@Override
	public void onCreate(Bundle savedInstanceState)  {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_hotel);
		mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		data = new Vector<RowData>();
	
		for(int i=0;i<namehotel.length;i++){
			rd = new RowData(i,namehotel[i],qualityhotel[i],adresshotel[i],phonehotel[i],mailhotel[i]);
			data.add(rd);
		}
	
	   CustomAdapter adapter = new CustomAdapter(this, R.layout.list_hotel_row,R.id.listhotel_Tv_name, R.id.listhotel_Tv_quality, R.id.listhotel_Tv_address, R.id.listhotel_Tv_telephone, R.id.listhotel_Tv_email, data);
	   setListAdapter(adapter);
	   getListView().setTextFilterEnabled(true);
	   

	   bntHome = (Button) findViewById(R.id.list_hotel_Btn_home);
	   bntFavorite = (Button) findViewById(R.id.list_hotel_Btn_favourite);
	   bntPlan = (Button) findViewById(R.id.list_hotel_Btn_plan);
	   bntAbout = (Button) findViewById(R.id.list_hotel_Btn_info);
	   bntBack = (Button) findViewById(R.id.list_hotel_Btn_back);
	  
	   bntHome.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			bntHome.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_trangchinh_selected));
			Intent i = new Intent(ListHotel.this, VietTravelActivity.class);
			startActivity(i);
		}
	   });
	   
	   bntFavorite.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				bntFavorite.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_uuthich_selected));
				Intent i = new Intent(ListHotel.this, FavoritesActivity.class);
				startActivity(i);
			}
	   });
	   
	   bntPlan.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				bntPlan.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_kehoach_selected));
				Intent i = new Intent(ListHotel.this, Plan.class);
				startActivity(i);
			}
	   });
	   
	   bntAbout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				bntAbout.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_thongtin_selected));
				Intent i = new Intent(ListHotel.this, About.class);
				startActivity(i);
			}
	   });
	   
	   bntBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				bntBack.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_back_selected));
				Intent i = new Intent(ListHotel.this, InformationTravelActivity.class);
				startActivity(i);
			}
	   });	
	   
	   
	   

	}
	
	private class RowData {
		protected int mId;
	    protected String mNameHotel;
	    protected String mQualityHotel;
	    protected String mAdressHotel;
	    protected String mPhoneHotel;
	    protected String mMailHotel;
	    public RowData(int id,String namehotel, String qualityhotel, String adresshotel, String phonehotel, String mailhotel){
	    mId=id;
	    mNameHotel = namehotel;
	    mQualityHotel = qualityhotel;
	    mAdressHotel = adresshotel;
	    mPhoneHotel = phonehotel;
	    mMailHotel = mailhotel;
	    }
	       @Override
	    public String toString() {
	    	   return mId+" "+mNameHotel+" "+mQualityHotel+" "+mAdressHotel+" "+mPhoneHotel+" "+mMailHotel;
	       }
	}
	  private class CustomAdapter extends ArrayAdapter<RowData> {
	 
		  public CustomAdapter(Context context, int resource,int namehotel, int qualityHotel, int adressHotel, int phoneHotel, int mailHotel, List<RowData> objects) {               
			  super(context, resource, objects);
		  }
	      @Override
	      public View getView(int position, View convertView, ViewGroup parent) {   
	    	  
	    	 		   
	    	  ViewHolder holder = null;
	    	  TextView namehotel = null;
	    	  TextView qualityhotel = null;
	    	  TextView adresshotel = null;
	    	  TextView phonehotel = null;
	    	  TextView mailhotel = null;
	    	  LoaderImageView image_listhotel=null;
	    	  
	    	  RowData rowData= getItem(position);
	    	  if(null == convertView){
	    		  convertView = mInflater.inflate(R.layout.list_hotel_row, null);
	    		  holder = new ViewHolder(convertView);
	    		  convertView.setTag(holder);
	    	  }
	  	   
	          holder = (ViewHolder) convertView.getTag();

	          namehotel = holder.getnamehotel();
	          qualityhotel = holder.getqualityhotel();
	          adresshotel = holder.getadresshotel();
	          phonehotel = holder.getphonehotel();
	          mailhotel = holder.getmailhotel();
	          namehotel.setText(rowData.mNameHotel);
	          qualityhotel.setText(rowData.mQualityHotel);
	          adresshotel.setText(rowData.mAdressHotel);
	          phonehotel.setText(rowData.mPhoneHotel);
	          mailhotel.setText(rowData.mMailHotel);
	          image_listhotel=holder.getImage();
	          
	          
	          
	          return convertView;
	      }
	      private class ViewHolder {
	    	  private View mRow;
	          private TextView namehotel = null;
	          private TextView qualityhotel = null;
	          private TextView adresshotel = null;
	          private TextView phonehotel = null;
	          private TextView mailhotel = null; 
	          public LoaderImageView image_listhotel = null;
	          public ViewHolder(View row) {
	        	  mRow = row;
	          }
	          
	          public TextView getnamehotel() {
	        	   if(null == namehotel){
	        		   namehotel = (TextView) mRow.findViewById(R.id.listhotel_Tv_name);
	               }
	        	   return namehotel;
	         }     
	          public TextView getqualityhotel() {
	        	   if(null == qualityhotel){
	        		   qualityhotel = (TextView) mRow.findViewById(R.id.listhotel_Tv_quality);
	               }
	        	   return qualityhotel;
	         }  
	          public TextView getadresshotel() {
	        	   if(null == adresshotel){
	        		   adresshotel = (TextView) mRow.findViewById(R.id.listhotel_Tv_address);
	               }
	        	   return adresshotel;
	         } 
	          public TextView getphonehotel() {
	        	   if(null == phonehotel){
	        		   phonehotel = (TextView) mRow.findViewById(R.id.listhotel_Tv_telephone);
	               }
	        	   return phonehotel;
	         }  
	          public TextView getmailhotel() {
	        	   if(null == mailhotel){
	        		   mailhotel = (TextView) mRow.findViewById(R.id.listhotel_Tv_email);
	               }
	        	   return mailhotel;
	         }  
	          public LoaderImageView getImage() {
		             if(null == image_listhotel){
		            	 image_listhotel = (LoaderImageView) mRow.findViewById(R.id.listhotel_Ima);
		             }
		             return image_listhotel;
		        }
	        
	     }
	} 
}
